# -*- coding:utf-8 -*-
import os, sys
import traceback
import time
from datetime import datetime, timedelta
sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), os.pardir))
from DataSupport.BasicDataSupport import BasicDataSupport
from CommonLib.mylog import mylog
from CommonLib.StockCal.TrainSummary import TrainSummary
from CommonLib.StockTool import StockTool


'''
作者：supeanut
创建时间：2016-12-12 22:16
功能描述：
相关配置：
	supeanut_config.xxx
历史改动：
	2016-12-13
'''
class PredictJob:
	def __init__(self):
		pass	

	def process(self, ):
		log = mylog('BasicDataJob.process', None)
		today = time.strftime('%Y-%m-%d',time.localtime(time.time()))
		# 判断交易日
		obj = StockTool()
		flag, all_trade_date = obj.get_trade_date()
		if flag is False:
			log.info('get trade date faild')
			return False, 'get trade date faild'
		if today not in all_trade_date:
			log.info('not trade date')
			return True, 'not trade date'
		# 预测并上传mongo
		obj = TrainSummary(filename='trainSet_allstock.csv', mem_mod=False)
		try:
			obj.day_predict(today)
		except:
			log.error(traceback.format_exc())

if __name__ == '__main__':
	obj = PredictJob()
	obj.process()
